# verification : https://atcoder.jp/contests/practice2/submissions/26355181

class DSU:
    # When data[x] < 0, x is a root and -data[x] is its tree size. When data[x] >= 0, data[x] is x's parent.
    data = []
    
    def __init__(self, _n = -1) -> None:
        if _n > 0:
            self.init(_n)
    
    def init(self, _n: int) -> None:
        self.n = _n
        self.data = [-1] * (_n + 1)
        self.components = _n

    def find(self, x: int) -> int:
        if self.data[x] < 0:
            return x

        self.data[x] = self.find(self.data[x])
        return self.data[x]

    def connected(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)

        if x == y:
            return False

        if (-self.data[x] < -self.data[y]):
            x, y = y, x

        self.data[x] += self.data[x]
        self.data[y] = x
        self.components -= 1
        return True

    def get_size(self, x: int) -> int:
        return -self.data[self.find(x)]

import sys

input = sys.stdin.readline

N, Q = map(int, input().split())
dsu = DSU(N)

while Q > 0:
    Q -= 1

    t, u, v = map(int, input().split())

    if t == 0:
        dsu.unite(u, v)
    else:
        print(int(dsu.connected(u, v)))
